package com.team.service.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.scripting.support.ResourceScriptSource;

@Configuration
public class RedisConfig {

    @Bean
    public DefaultRedisScript<String> idGeneratorScript() {
        DefaultRedisScript<String> redisScript = new DefaultRedisScript<>();
        // 设置脚本返回类型为String
        redisScript.setResultType(String.class);
        // 设置Lua脚本位置，脚本文件需放在resources/scripts/目录下
        redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("scripts/id_generator.lua")));
        return redisScript;
    }
} 